/**
 * 
 */
angular.module('app.service.feedback', ['ngResource'])

//feedback
    .service('FeedbackService', ['$resource','UserService', function ($resource,UserService) {
        var resource = $resource(localhost + "feedback/:seqid");
        
        //获取列表
        this.getlist = function () {
            var promise_result = resource.query({});
            //
            var userinfo_map = {};
            function fill_userinfo(list, i) {
                if (i >= list.length) {
                    return;
                }
                var item = list[i];
                if (userinfo_map[item.userid]) {
                    item.username = userinfo_map[item.userid];
                    fill_userinfo(list, i + 1);
                } else {
                    UserService.getuserbyid(item.userid).$promise.then(function(data){
                        item.username = data.name;
                        userinfo_map[item.userid] = data.name;
                        fill_userinfo(list, i + 1);
                    }, function(error){
                        console.log(error);
                    });
                }
            }
            promise_result.$promise.then(function(list){
                fill_userinfo(list, 0);
            });
            //
            return promise_result;
        }
    }])
;